package com.ml.mall.api.credit;

import com.ml.mall.bean.base.ApiRestResult;
import com.ml.mall.bean.req.credit.*;
import com.ml.mall.consts.PermissionConst;
import com.ml.mall.service.credit.SysCreditRecordService;
import com.ml.mall.service.credit.SysCreditService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 *   @description    :description 
 *   @author         :zxm
 *   @date           :2021/5/19
 *   @version        :1.0
**/
@Api(tags = "【auth】公司余额相关接口")
@RestController
@RequestMapping("/credit")
public class CreditController {

    @Autowired
    private SysCreditService sysCreditService;
    @Autowired
    private SysCreditRecordService sysCreditRecordService;

    @ApiOperation(value = "公司余额新增")
    @PostMapping("/new")
//  @RequiresPermissions(PermissionConst.CREDIT_NEW) //未发现调用
    public ApiRestResult creditNew(@RequestBody @Valid CreditNewDto dto){
        sysCreditService.createCredit(dto);
        return ApiRestResult.ok();
    }

    @ApiOperation(value = "公司余额编辑")
    @PostMapping("/edit")
//  @RequiresPermissions(PermissionConst.CREDIT_EDIT) //未发现调用
    public ApiRestResult creditEdit(@RequestBody @Valid CreditEditDto dto){
        sysCreditService.creditEdit(dto);
        return ApiRestResult.ok();
    }

    @ApiOperation(value = "公司余额单个查询")
    @PostMapping("/query_one")
//  @RequiresPermissions(PermissionConst.CREDIT_QUERY_ONE)
    public ApiRestResult creditQueryOne(@RequestBody CreditQueryOneDto dto){
        return ApiRestResult.ok(sysCreditService.queryOneCredit(dto));
    }
    @ApiOperation(value = "公司余额分页查询")
    @PostMapping("/query_page")
//  @RequiresPermissions(PermissionConst.CREDIT_QUERY_PAGE)
    public ApiRestResult creditQueryPage(@RequestBody CreditQueryDto dto){
        return ApiRestResult.ok(sysCreditService.queryPageCredit(dto));
    }
    @ApiOperation(value = "公司余额变动记录新增")
    @PostMapping("/add_record")
//  @RequiresPermissions(PermissionConst.CREDIT_ADD_RECORD)
    public ApiRestResult creditRecordAdd(@RequestBody @Valid CreditRecordNewDto dto){
        return sysCreditRecordService.createCreditRecord(dto);
    }

    @ApiOperation(value = "公司余额变动记录分页查询")
    @PostMapping("/query_change_record")
//  @RequiresPermissions(PermissionConst.CREDIT_QUERY_CHANGE_RECORD)
    public ApiRestResult creditRecordQueryPage(@RequestBody CreditRecordQueryDto dto){
        return ApiRestResult.ok(sysCreditRecordService.queryPageCreditRecord(dto));
    }
}
